import math
import vtkmodules.all as vtk


class VAttribute:
    name = ""
    # #️⃣ 默认一组数据是3个值 即 x y z
    size = 3
    value: vtk.vtkDataArray = None
    dx = None
    dy = None
    dz = None
    magtitude = None

    def __init__(self, name, value, size):
        self.name = name
        self.value = value
        self.size = size
        self.dx = vtk.vtkFloatArray()
        self.dy = vtk.vtkFloatArray()
        self.dz = vtk.vtkFloatArray()
        self.magtitude = vtk.vtkFloatArray()
        self.parse()

    def parse(self):
        if self.size == 3:
            t: int = int(self.value.GetSize() / 3)
            for i in range(t):
                x = self.value.GetValue(3 * i)
                y = self.value.GetValue(3 * i + 1)
                z = self.value.GetValue(3 * i + 2)
                magtitude = math.sqrt(x * x + y * y + z * z)
                self.dx.InsertNextValue(x)
                self.dy.InsertNextValue(y)
                self.dz.InsertNextValue(z)
                self.magtitude.InsertNextValue(magtitude)
        else:
            t: int = int(self.value.GetSize() / 1)
            for i in range(t):
                x = self.value.GetValue(1 * i)
                self.dx.InsertNextValue(x)
